package org.sippr.controller;

import org.sippr.pojo.Result;
import org.sippr.pojo.WordCue;
import org.sippr.service.WordCueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/word/cue")
public class WordCueController {
    @Autowired
    WordCueService wordCueService;

    //新增
    @PostMapping
    public Result add(@RequestBody @Validated WordCue value) {
        WordCue wordCue = wordCueService.findByName(value.getChName());
        if (wordCue != null) {
            return Result.error("名称已存在！");
        }
        wordCueService.add(value);
        return Result.success();
    }

    //获取指定分类
    @GetMapping
    public Result list(Integer clsId) {
        List<WordCue> wordCueList = wordCueService.findByClsId(clsId);
        return Result.success(wordCueList);
    }

    //删除
    @DeleteMapping
    public Result delete(Integer id) {
        wordCueService.delete(id);
        return Result.success();
    }

}
